﻿using VisualWip.Core.Interfaces;
using VisualWip.Core.SlotsProviders;

namespace VisualWip.Core.Columns
{
    public class WorkSingleColumn : WorkColumnBase
    {
        private bool _availibility;
        private IQuery _firstQuery;

        public WorkSingleColumn(IWorkItemProviderFactory workItemProviderFactory)
            : base(workItemProviderFactory)
        {
            Availibility = true;
        }


        public override IQuery Query
        {
            get { return FirstQuery; }
        }

        public override ISlotsProvider SlotsProvider
        {
            get { return new SlotsProvider(Availibility); }
        }

        public bool Availibility
        {
            get { return _availibility; }
            set
            {
                if (value != _availibility)
                {
                    _availibility = value;
                    OnPropertyChanged(this, () => Availibility);
                }
            }
        }

        public IQuery FirstQuery
        {
            get { return _firstQuery; }
            set
            {
                if (value != _firstQuery)
                {
                    _firstQuery = value;
                    OnPropertyChanged(this, () => FirstQuery);
                    OnPropertyChanged(this, () => Query);
                }
            }
        }

        public override PersistenceTree Persist(string name)
        {
            PersistenceTree settings = base.Persist(name);
            settings.Add(() => Availibility);
            settings.AddChild(() => FirstQuery);
            return settings;
        }

        public override void Load(PersistenceTree settings)
        {
            base.Load(settings);
            Availibility = settings.Get(() => Availibility,true);
            FirstQuery = settings.GetChild(() => FirstQuery);
        }
    }
}